#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

const int N = 4e5 + 5, inf = 0x3f3f3f3f;
int n, m, tot, sum, mon[N], w[N], pre[N];

bool dfs(int cur, int pre, int waste) {
  if (!cur) return true;
  if (sum - waste < tot) return false;
  bool res;
  for (int i = (w[cur] == w[cur + 1] ? pre : 1); i <= n; ++i) {
    if (mon[i] < w[cur]) continue;
    mon[i] -= w[cur];
    res = dfs(cur - 1, i, waste + (mon[i] < w[1] ? mon[i] : 0));
    mon[i] += w[cur];
    if (res) return true;
  }
  return false;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("canteen.in", "r", stdin);
  freopen("canteen.out", "w", stdout);
#endif
#endif

  read(n);
  for (int i = 1; i <= n; ++i) sum += read(mon[i]);
  std::sort(mon + 1, mon + n + 1,
            [](const int lhs, const int rhs) { return lhs > rhs; });
  read(m);
  for (int i = 1; i <= m; ++i) read(w[i]);
  std::sort(w + 1, w + m + 1);
  for (int i = 1; i <= m; ++i) pre[i] = pre[i - 1] + w[i];

  int l = 0, r = m, mid;
  while (l < r) {
    mid = (l + r + 1) >> 1;
    if (pre[mid] <= sum && (tot = pre[mid]) && dfs(mid, 1, 0)) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  printf("%d", l);
  return 0;
}